import { EventKey } from '../common/Key';
cc.Class({
    extends: require('BaseScene'),

    properties: {
        labVersion: cc.Label,
    },

    onLoad() {
        this._super();
        // G.game.loadScene('SceneGame');
        
    },

    start() {
        this._registEvent();
        this._initVersion();
        G.partner.createGameClub();
    },

    onEnable(){
        this._super();
        G.ad.show(G.ad.AD_BANNER);
    },
    onDisable(){
        this._super();
        G.ad.hide(G.ad.AD_BANNER);
    },

    _initVersion() {
        this.labVersion.string = G.config.getVersion();
    },

    onDestroy() {
        this._unRegistEvent();
        G.partner.hideGameClub();
    },

    _registEvent() {
        G.onFire.on(EventKey.EVENT_ENTER_PANEL, this._onFire, this);
        G.onFire.on(EventKey.EVENT_EXIT_PANEL, this._onFire, this);

    },
    _unRegistEvent() {
        G.onFire.off(EventKey.EVENT_ENTER_PANEL, this._onFire, this);
        G.onFire.off(EventKey.EVENT_EXIT_PANEL, this._onFire, this);
    },

    _onFire(eventName, param) {
        if (eventName == EventKey.EVENT_ENTER_PANEL) {
            G.partner.hideGameClub();
        } else if (eventName == EventKey.EVENT_EXIT_PANEL) {
            G.partner.showGameClub();
        }
    },

    buttonListener(button) {
        let name = button.node.name;
        if (name == 'btnStartGame') {
            G.game.loadScene('SceneGame');
        } else if (name == 'btnShare') {
            G.partner.sendEvent('分享', { '类型': 'home' });
            G.partner.share({ title: '这一关你能闯过去吗？' }, () => {

            });
        } else if (name == 'btnRank') {
            G.ui.openUI('PanelRank');
        } else if (name == "btnRecord") {
            G.ui.openUI('PanelRecord')
        }

    },

    // update (dt) {},
});
